#ifndef LEVELSCENE_H
#define LEVELSCENE_H

#include "gamescene.h"
#include <QWidget>
#include <QApplication>
#include <QMouseEvent>
#include <QList>
#include <QPixmap>
#include <QImage>
#include <QPointF>
#include <QGraphicsPixmapItem>
#include <QTimer>
#include <QPainter>

#include "gamebackground.h"
#include "toolbutton.h"
#include "minimap.h"
#include "building.h"
#include "optionspanel.h"
#include "tools.h"
#include "gameitems.h"
#include "statsdisplay.h"

//Pathfinding stuff
#include "pathfinder.h"
#include "pathmapvisualizer.h"
#include <stdlib.h>

#define RESOURCE_DIR QApplication::applicationDirPath() + "/../../resources"

class LevelScene : public GameScene
{
    Q_OBJECT

public:
    LevelScene(QPixmap mapPixmap, QImage mapMask, QWidget *parent);

    ToolButton * addTool(QString caption, QPixmap toolIcon);
    Building * addBuilding(QPoint enterence, QPointF position, QPixmap buildingPixmap);
    Person * addPerson(QPixmap personPixmap, Building * startingBuilding);

    void start();
    void pauseScene();

    QList<Building*> buildings;

public slots:
    void toolClicked(ToolButton * sender);
    void buildingClicked(Building * sender);
    void mapClicked(QPointF point);
    void pathSolved(std::vector<void*> path, QObject * receiver);
    void enterBuilding(Person * person, Building * building);
    void leaveBuilding(Person * person, Building * building);
    void updateStats();

    void resumeScene();
    void endScene(GameScene::GameScenes nextScene);

signals:
    void startPeople();
    void stopPeople();
	
protected:
    QList<ToolButton*> tools;
    ToolButton * currentTool;
    QList<Person*> people;
    StatsDisplay * stats;
    PathFinder * pathFinder;
    GameBackground * buildingImage;

    void keyPressEvent(QKeyEvent * event);
    void checkCollisions();
    void timerEvent(QTimerEvent *event);

    //Tools
    ToolButton * quarantineTool;
    ToolButton * sterilizationTool;
    ToolButton * vacceneTool;
    ToolButton * antiviralTool;
    ToolButton * gammaglobulinTool;
    ToolButton * geneTherapyTool;

private:
    // Stuff for the map
    GameBackground * map;
    void saveBuildingImage();

    // All the stuff for the tools panel
    QGraphicsView * panelView;
    QGraphicsScene * panelScene;
    GameBackground * panelBackground;
    QList<QGraphicsPixmapItem*> roadBlocks;

    // The minimap object
    MiniMap * miniMap;

    // The options panel object
    OptionsPanel * optionsPanel;

    PathMapVisualizer * visualizer;

    QTimer * statsTimer;


};

#endif // LEVELSCENE_H
